import asyncio
from typing import Callable, Coroutine
from pyrogram.types import Message
from pyrogram import Client


def auto_delete_message(delay=30):
    def decorator(
        func: Callable[
            [Client, Message],
            Coroutine[None, None, Message | tuple[Message, bool] | None],
        ]
    ):
        async def wrapper(client, message: Message):
            sent_message = await func(client, message)
            if isinstance(sent_message, tuple):
                sent_message, delete_message = sent_message
                if not delete_message:
                    return
            await asyncio.sleep(delay)
            if sent_message:
                await sent_message.delete()

        return wrapper

    return decorator
